// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Requests;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using Elastic.Transport;
using Elastic.Transport.Extensions;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.MachineLearning;

public sealed partial class GetModelSnapshotsRequestParameters : RequestParameters
{
	/// <summary>
	/// <para>
	/// Skips the specified number of snapshots.
	/// </para>
	/// </summary>
	public int? From { get => Q<int?>("from"); set => Q("from", value); }

	/// <summary>
	/// <para>
	/// Specifies the maximum number of snapshots to obtain.
	/// </para>
	/// </summary>
	public int? Size { get => Q<int?>("size"); set => Q("size", value); }
}

/// <summary>
/// <para>
/// Get model snapshots info.
/// </para>
/// </summary>
public sealed partial class GetModelSnapshotsRequest : PlainRequest<GetModelSnapshotsRequestParameters>
{
	public GetModelSnapshotsRequest(Elastic.Clients.Elasticsearch.Serverless.Id jobId, Elastic.Clients.Elasticsearch.Serverless.Id? snapshotId) : base(r => r.Required("job_id", jobId).Optional("snapshot_id", snapshotId))
	{
	}

	public GetModelSnapshotsRequest(Elastic.Clients.Elasticsearch.Serverless.Id jobId) : base(r => r.Required("job_id", jobId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningGetModelSnapshots;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.get_model_snapshots";

	/// <summary>
	/// <para>
	/// Skips the specified number of snapshots.
	/// </para>
	/// </summary>
	[JsonIgnore]
	public int? From { get => Q<int?>("from"); set => Q("from", value); }

	/// <summary>
	/// <para>
	/// Specifies the maximum number of snapshots to obtain.
	/// </para>
	/// </summary>
	[JsonIgnore]
	public int? Size { get => Q<int?>("size"); set => Q("size", value); }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>desc</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("desc")]
	public bool? Desc { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>end</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("end")]
	public DateTimeOffset? End { get; set; }
	[JsonInclude, JsonPropertyName("page")]
	public Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Page? Page { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>sort</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("sort")]
	public Elastic.Clients.Elasticsearch.Serverless.Field? Sort { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>start</c> query parameter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("start")]
	public DateTimeOffset? Start { get; set; }
}

/// <summary>
/// <para>
/// Get model snapshots info.
/// </para>
/// </summary>
public sealed partial class GetModelSnapshotsRequestDescriptor<TDocument> : RequestDescriptor<GetModelSnapshotsRequestDescriptor<TDocument>, GetModelSnapshotsRequestParameters>
{
	internal GetModelSnapshotsRequestDescriptor(Action<GetModelSnapshotsRequestDescriptor<TDocument>> configure) => configure.Invoke(this);

	public GetModelSnapshotsRequestDescriptor(Elastic.Clients.Elasticsearch.Serverless.Id jobId, Elastic.Clients.Elasticsearch.Serverless.Id? snapshotId) : base(r => r.Required("job_id", jobId).Optional("snapshot_id", snapshotId))
	{
	}

	public GetModelSnapshotsRequestDescriptor(Elastic.Clients.Elasticsearch.Serverless.Id jobId) : base(r => r.Required("job_id", jobId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningGetModelSnapshots;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.get_model_snapshots";

	public GetModelSnapshotsRequestDescriptor<TDocument> From(int? from) => Qs("from", from);
	public GetModelSnapshotsRequestDescriptor<TDocument> Size(int? size) => Qs("size", size);

	public GetModelSnapshotsRequestDescriptor<TDocument> JobId(Elastic.Clients.Elasticsearch.Serverless.Id jobId)
	{
		RouteValues.Required("job_id", jobId);
		return Self;
	}

	public GetModelSnapshotsRequestDescriptor<TDocument> SnapshotId(Elastic.Clients.Elasticsearch.Serverless.Id? snapshotId)
	{
		RouteValues.Optional("snapshot_id", snapshotId);
		return Self;
	}

	private bool? DescValue { get; set; }
	private DateTimeOffset? EndValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Page? PageValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor PageDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor> PageDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field? SortValue { get; set; }
	private DateTimeOffset? StartValue { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>desc</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor<TDocument> Desc(bool? desc = true)
	{
		DescValue = desc;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>end</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor<TDocument> End(DateTimeOffset? end)
	{
		EndValue = end;
		return Self;
	}

	public GetModelSnapshotsRequestDescriptor<TDocument> Page(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Page? page)
	{
		PageDescriptor = null;
		PageDescriptorAction = null;
		PageValue = page;
		return Self;
	}

	public GetModelSnapshotsRequestDescriptor<TDocument> Page(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor descriptor)
	{
		PageValue = null;
		PageDescriptorAction = null;
		PageDescriptor = descriptor;
		return Self;
	}

	public GetModelSnapshotsRequestDescriptor<TDocument> Page(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor> configure)
	{
		PageValue = null;
		PageDescriptor = null;
		PageDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>sort</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor<TDocument> Sort(Elastic.Clients.Elasticsearch.Serverless.Field? sort)
	{
		SortValue = sort;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>sort</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor<TDocument> Sort<TValue>(Expression<Func<TDocument, TValue>> sort)
	{
		SortValue = sort;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>sort</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor<TDocument> Sort(Expression<Func<TDocument, object>> sort)
	{
		SortValue = sort;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>start</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor<TDocument> Start(DateTimeOffset? start)
	{
		StartValue = start;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (DescValue.HasValue)
		{
			writer.WritePropertyName("desc");
			writer.WriteBooleanValue(DescValue.Value);
		}

		if (EndValue is not null)
		{
			writer.WritePropertyName("end");
			JsonSerializer.Serialize(writer, EndValue, options);
		}

		if (PageDescriptor is not null)
		{
			writer.WritePropertyName("page");
			JsonSerializer.Serialize(writer, PageDescriptor, options);
		}
		else if (PageDescriptorAction is not null)
		{
			writer.WritePropertyName("page");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor(PageDescriptorAction), options);
		}
		else if (PageValue is not null)
		{
			writer.WritePropertyName("page");
			JsonSerializer.Serialize(writer, PageValue, options);
		}

		if (SortValue is not null)
		{
			writer.WritePropertyName("sort");
			JsonSerializer.Serialize(writer, SortValue, options);
		}

		if (StartValue is not null)
		{
			writer.WritePropertyName("start");
			JsonSerializer.Serialize(writer, StartValue, options);
		}

		writer.WriteEndObject();
	}
}

/// <summary>
/// <para>
/// Get model snapshots info.
/// </para>
/// </summary>
public sealed partial class GetModelSnapshotsRequestDescriptor : RequestDescriptor<GetModelSnapshotsRequestDescriptor, GetModelSnapshotsRequestParameters>
{
	internal GetModelSnapshotsRequestDescriptor(Action<GetModelSnapshotsRequestDescriptor> configure) => configure.Invoke(this);

	public GetModelSnapshotsRequestDescriptor(Elastic.Clients.Elasticsearch.Serverless.Id jobId, Elastic.Clients.Elasticsearch.Serverless.Id? snapshotId) : base(r => r.Required("job_id", jobId).Optional("snapshot_id", snapshotId))
	{
	}

	public GetModelSnapshotsRequestDescriptor(Elastic.Clients.Elasticsearch.Serverless.Id jobId) : base(r => r.Required("job_id", jobId))
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningGetModelSnapshots;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.get_model_snapshots";

	public GetModelSnapshotsRequestDescriptor From(int? from) => Qs("from", from);
	public GetModelSnapshotsRequestDescriptor Size(int? size) => Qs("size", size);

	public GetModelSnapshotsRequestDescriptor JobId(Elastic.Clients.Elasticsearch.Serverless.Id jobId)
	{
		RouteValues.Required("job_id", jobId);
		return Self;
	}

	public GetModelSnapshotsRequestDescriptor SnapshotId(Elastic.Clients.Elasticsearch.Serverless.Id? snapshotId)
	{
		RouteValues.Optional("snapshot_id", snapshotId);
		return Self;
	}

	private bool? DescValue { get; set; }
	private DateTimeOffset? EndValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Page? PageValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor PageDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor> PageDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field? SortValue { get; set; }
	private DateTimeOffset? StartValue { get; set; }

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>desc</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor Desc(bool? desc = true)
	{
		DescValue = desc;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>end</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor End(DateTimeOffset? end)
	{
		EndValue = end;
		return Self;
	}

	public GetModelSnapshotsRequestDescriptor Page(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.Page? page)
	{
		PageDescriptor = null;
		PageDescriptorAction = null;
		PageValue = page;
		return Self;
	}

	public GetModelSnapshotsRequestDescriptor Page(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor descriptor)
	{
		PageValue = null;
		PageDescriptorAction = null;
		PageDescriptor = descriptor;
		return Self;
	}

	public GetModelSnapshotsRequestDescriptor Page(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor> configure)
	{
		PageValue = null;
		PageDescriptor = null;
		PageDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>sort</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor Sort(Elastic.Clients.Elasticsearch.Serverless.Field? sort)
	{
		SortValue = sort;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>sort</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor Sort<TDocument, TValue>(Expression<Func<TDocument, TValue>> sort)
	{
		SortValue = sort;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>sort</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor Sort<TDocument>(Expression<Func<TDocument, object>> sort)
	{
		SortValue = sort;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Refer to the description for the <c>start</c> query parameter.
	/// </para>
	/// </summary>
	public GetModelSnapshotsRequestDescriptor Start(DateTimeOffset? start)
	{
		StartValue = start;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (DescValue.HasValue)
		{
			writer.WritePropertyName("desc");
			writer.WriteBooleanValue(DescValue.Value);
		}

		if (EndValue is not null)
		{
			writer.WritePropertyName("end");
			JsonSerializer.Serialize(writer, EndValue, options);
		}

		if (PageDescriptor is not null)
		{
			writer.WritePropertyName("page");
			JsonSerializer.Serialize(writer, PageDescriptor, options);
		}
		else if (PageDescriptorAction is not null)
		{
			writer.WritePropertyName("page");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.PageDescriptor(PageDescriptorAction), options);
		}
		else if (PageValue is not null)
		{
			writer.WritePropertyName("page");
			JsonSerializer.Serialize(writer, PageValue, options);
		}

		if (SortValue is not null)
		{
			writer.WritePropertyName("sort");
			JsonSerializer.Serialize(writer, SortValue, options);
		}

		if (StartValue is not null)
		{
			writer.WritePropertyName("start");
			JsonSerializer.Serialize(writer, StartValue, options);
		}

		writer.WriteEndObject();
	}
}